Skip to content

refactor(lsp): share GitHub-release and dotnet-tool install logic across downloaded servers - #161

Merged
amondnet merged 4 commits into
mainfrom
amondnet/lsp-release-download-helper
Nov 23, 2026
Merged

amondnet merged 4 commits into
mainfrom
amondnet/lsp-release-download-helper

Conversation

@amondnet

@amondnet amondnet commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SonarCloud still reports duplication in the language servers that download a binary instead of installing from npm. csharp and fsharp had identical dotnet tool install code. lua, terraform and texlab each repeated the same steps: fetch the latest GitHub release, pick the asset, download, extract, check the binary, chmod. This follows #159, which shares the install logic for the npm-based servers. The two PRs touch different files and are independent.

What changed

  • New packages/lsp/src/server/github-release.ts with serverCacheDir(name), findCachedBinary(name, ...dirs) and downloadReleaseBinary(spec, destDir, bin).
    • findCachedBinary checks PATH first, then the cache dirs. It skips an unset PATH instead of producing an undefined: entry.
    • downloadReleaseBinary fetches releases/latest and finds the platform asset through spec.assetName(release). It downloads into a temp dir that it always removes, unzips .zip assets (extractZip) or runs tar -xzf through Bun.spawn for everything else, then checks bin and chmods it 755. Any failure is logged and returns false.
  • terraform and texlab call the helper directly. lua keeps its per-attempt staging dir and publishInstall, and downloads into the staging dir through the helper.
  • New packages/lsp/src/server/dotnet-tool.ts with dotnetToolServer({ id, tool, extensions, rootMarkers }). csharp.ts and fsharp.ts are now built from it.

Scope

Covers the binary-download and dotnet-tool servers only. The npm-based servers are in #159. Cache dirs and the auto_install gate are unchanged.

Tradeoffs

downloadAndExtract from @pleaseai/binaries was not used. Its tar extraction goes through execSync in a shell, and that shell looks up tar on PATH. A PATH without tar (as in the unit test) fails where the old Bun.spawn call worked. Possible follow-up: switch that helper to Bun.spawn.

Blast radius

  • Cache dirs are unchanged, so existing installs under $HOME/.cache/dora/... keep working.
  • Download and extract errors used to throw out of spawn. Now they are logged and spawn returns undefined.
  • Archives are downloaded into a temp dir instead of the cache dir.

Verification

  • bun test packages/lsp/test/unit: 195 pass. bun run typecheck and eslint are clean.
  • New tests in packages/lsp/test/unit/auto-install.test.ts: csharp-ls runs a tool that is already in the cache, and texlab downloads its release binary with a stubbed fetch. The existing lua download, cache, and gate-off tests still pass.

Related issue

None.

Checklist

  • PR title follows Conventional Commits
  • Tests added or updated, and the suite passes (bun run test)
  • Lint/format pass (bun run lint)
  • Documentation updated if behavior changed (no user-facing behavior change)
  • No breaking change, or a BREAKING CHANGE: note is included

Summary by cubic

Shares GitHub-release download logic across Lua, Terraform, and Texlab, and .NET tool installation across C# and F#. This removes duplicated install code while preserving existing cache locations and auto-install behavior.

  • Release lookups and downloads are wrapped in error boundaries, so offline or malformed responses log and return no server instead of propagating from spawn. Release-info requests have a 30-second timeout.
  • Downloaded server binaries are made executable by their owner only, since they live in the user's cache dir.
  • Lua keeps its staged publish flow; a kept install missing its execute bit is re-enabled.
  • Adds tests for using a cached csharp-ls, installing Texlab from a release, and Terraform returning undefined on release lookup failure.

Written for commit c9372e9. Summary will update on new commits.

Turn on auto-fix

…oss downloaded servers

github-release.ts holds the shared download logic: serverCacheDir,
findCachedBinary, and downloadReleaseBinary. downloadReleaseBinary
fetches the latest release and finds this platform's asset. It
downloads into a temp dir and unzips or untars into the destination
dir. It then checks the binary and makes it executable.

terraform, texlab and lua now call it. lua still uses its staging dir
and publishInstall.

dotnet-tool.ts adds dotnetToolServer, which csharp and fsharp now
build from.

The cache dirs are unchanged. This clears the remaining duplication
SonarCloud reports.

New tests: a csharp-ls tool already in the cache is used, and texlab
downloads its release.
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.81081% with 54 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/lsp/src/server/dotnet-tool.ts 41.17% 30 Missing ⚠️
packages/lsp/src/server/github-release.ts 80.00% 15 Missing ⚠️
packages/lsp/src/server/lua.ts 76.19% 5 Missing ⚠️
packages/lsp/src/server/terraform.ts 71.42% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the LSP server implementations by introducing shared helpers (dotnet-tool.ts and github-release.ts) to centralize the installation and spawning of .NET tools and GitHub release binaries, significantly reducing code duplication across several language servers. Unit tests have also been added to verify these auto-installation behaviors. Feedback on the changes highlights a high-severity issue in github-release.ts where unhandled network exceptions and a missing User-Agent header could cause failures during GitHub API calls, as well as a medium-severity issue in dotnet-tool.ts where unhandled exceptions during the dotnet tool installation process could lead to application instability.

Comment thread packages/lsp/src/server/dotnet-tool.ts Resolved
SonarCloud S2612 flagged the 0o755 chmod in downloadReleaseBinary. The binary lives in the
user's own cache dir and only that user runs it.
@amondnet
amondnet marked this pull request as ready for review November 23, 2026 03:13

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitar has auto-approved this PR (configure)

@gitar-bot gitar-bot Bot added the gitar-approved Added by Gitar label Nov 23, 2026
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Shares GitHub release downloads across Lua, Terraform, and Texlab, and .NET tool installation across C# and F#.

  • Lua, Terraform, and TexLab share one GitHub release installer.
  • C# and F# share one .NET tool installer.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Language server starts] --> B{Binary on PATH or cached?}
  B -->|Yes| C[Start binary]
  B -->|No| D{Auto-install enabled?}
  D -->|No| E[Return no server]
  D -->|Yes| F{Server type}
  F -->|C# or F#| G[Install dotnet tool]
  F -->|Lua, Terraform, or Texlab| H[Fetch release with 30-second timeout]
  H --> I[Download and extract]
  I --> J[Check binary and set execute permission]
  J --> K[Lua publishes staged install]
  J --> C
  K --> C
  G --> C
Loading

Reviews (3) · Last reviewed commit: "chore(lsp): apply AI code review suggest..." · Reviewed by Greptile

Comment thread packages/lsp/src/server/lua.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files

Architecture diagram
sequenceDiagram
    participant Server as Language Server (csharp/fsharp/lua/terraform/texlab)
    participant Helper as Shared Install Helper<br/>(github-release.ts / dotnet-tool.ts)
    participant FS as File System<br/>($HOME/.cache/dora/*)
    participant GitHub as GitHub API<br/>(api.github.com)
    participant Spawn as Spawned Process<br/>(dotnet/tar/LSP server)

    Note over Server,Helper: Server activation flow (per language)

    Server->>Helper: spawn(root) - request server binary
    Helper->>FS: findCachedBinary(name, cacheDirs)
    
    alt Binary found on PATH or cache
        FS-->>Helper: binary path
        Helper->>Spawn: spawn(bin, [], { cwd: root })
        Spawn-->>Helper: process handle
        Helper-->>Server: { process }
    
    else Binary not cached
        FS-->>Helper: null
        
        alt dotnet tool server (csharp/fsharp)
            Helper->>Spawn: check 'dotnet' on PATH
            alt dotnet missing
                Spawn-->>Helper: not found
                Helper-->>Server: undefined (log warning)
            else dotnet present
                Helper->>Helper: check autoInstallDisabled(serverId)
                alt auto-install disabled
                    Helper-->>Server: undefined
                else auto-install enabled
                    Helper->>FS: mkdir(cacheDir)
                    Helper->>Spawn: dotnet tool install <tool> --tool-path <cache>
                    Spawn-->>Helper: exit code
                    alt install success
                        Helper->>FS: construct binary path
                        Helper->>Spawn: spawn(bin, [], { cwd: root })
                        Spawn-->>Helper: process handle
                        Helper-->>Server: { process }
                    else install failed
                        Helper-->>Server: undefined (log error)
                    end
                end
            end
        
        else GitHub release server (lua/terraform/texlab)
            Helper->>Helper: check autoInstallDisabled(serverId)
            alt auto-install disabled
                Helper-->>Server: undefined
            else auto-install enabled
                Helper->>GitHub: fetch /repos/{repo}/releases/latest
                GitHub-->>Helper: release JSON
                Helper->>Helper: find asset by platform (assetName)
                alt asset found
                    Helper->>FS: create temp dir (os.tmpdir)
                    Helper->>GitHub: download asset to temp dir
                    GitHub-->>Helper: archive file
                    Helper->>Spawn: extract archive (tar -xzf or unzip)
                    Spawn-->>Helper: extraction result
                    alt extract success
                        Helper->>FS: verify binary exists
                        Helper->>FS: chmod binary (0o700, non-Windows)
                        
                        alt lua (staged install)
                            Helper->>FS: stage binary in temp dir
                            Helper->>FS: publishInstall() - atomic move to cache
                            FS-->>Helper: success/failure
                        else terraform/texlab (direct install)
                            Helper->>FS: extract directly to cache dir
                        end
                        
                        Helper->>FS: cleanup temp dir
                        Helper->>Spawn: spawn(bin, [], { cwd: root })
                        Spawn-->>Helper: process handle
                        Helper-->>Server: { process }
                    else extract failed
                        Helper->>FS: cleanup temp dir
                        Helper-->>Server: undefined (log error)
                    end
                else asset not found
                    Helper-->>Server: undefined (log error)
                end
            end
        end
    end
Loading

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

- downloadReleaseBinary: the release lookup (fetch, JSON parse, asset name) now runs inside
  an error boundary, so offline or malformed responses log and return false
- dotnet-tool: catch install errors; read stderr while waiting for exit
- lua-ls: restore chmod on the published binary so a kept install that lost its execute
  bit runs again
- test: terraform returns undefined when the release lookup fails

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitar has auto-approved this PR (configure)

@amondnet

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the LSP server implementations by extracting shared logic for installing and spawning servers. It introduces dotnet-tool.ts for NuGet-based tools and github-release.ts for downloading and extracting binaries from GitHub releases, significantly reducing code duplication across csharp, fsharp, lua, terraform, and texlab servers. Unit tests have also been updated to cover these new installation flows. The review feedback highlights two key issues in github-release.ts: a potential deadlock and uncaught synchronous error when spawning the tar process, and a missing timeout on the GitHub API fetch request which could cause the process to hang indefinitely.

- bound the GitHub release-info request with a 30s AbortSignal timeout
- extract tar archives with stdout ignored and stderr read while waiting for exit
@sonarqubecloud

Copy link
Copy Markdown

@amondnet

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the LSP server implementations by centralizing the installation logic. It introduces dotnet-tool.ts for .NET tool installations and github-release.ts for downloading and extracting binaries from GitHub releases, simplifying csharp.ts, fsharp.ts, lua.ts, terraform.ts, and texlab.ts. Feedback on these changes includes ensuring the destination directory is created before extracting zip archives in github-release.ts to prevent clean-install failures, and removing a redundant fs.chmod call in lua.ts since permissions are already set during the download process.

Comment thread packages/lsp/src/server/lua.ts Resolved

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitar has auto-approved this PR (configure)

@gitar-bot

gitar-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

Refactoring language-server downloads changes failure handling; install errors now return no server, potentially leaving affected projects without that language server.

Shares GitHub-release download and dotnet-tool install logic across Lua, Terraform, Texlab, C#, and F# language servers, removing duplicated install code. The release-info fetch and JSON error that previously escaped the helper and made spawn throw is now handled, so failures are logged and return no server. No open issues found.

✅ 1 closed
✅ Edge Case: Release-info fetch/JSON errors escape the helper and make spawn throw

📄 packages/lsp/src/server/github-release.ts:37-45
In downloadReleaseBinary, the fetch(...releases/latest), response.json() and spec.assetName(release) calls all run before the try block. If the machine is offline, DNS fails, GitHub returns a non-JSON body, or the payload has no assets array, the error propagates up through LuaLsServer/TerraformServer/TexlabServer.spawn. Spawn then throws, when the helper is documented to return false after logging and the PR says spawn returns undefined on failure. To fix it, start the try before the release lookup, or wrap that part in its own try/catch that logs and returns false.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Approved

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 4 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@amondnet
amondnet merged commit 490228f into main Nov 23, 2026
11 checks passed
@amondnet
amondnet deleted the amondnet/lsp-release-download-helper branch November 23, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gitar-approved Added by Gitar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants